using Unity.Entities;
using Unity.Mathematics;
using UnityEngine;

namespace DOTS.DOD.LESSON8
{
    struct MultiCubesGenerator : IComponentData
    {
        public Entity RedCubeProtoType;
        public Entity GreenCubeProtoType;
        public Entity BlueCubeProtoType;
        public int GenerationTotalCount;
        public int GenerationNumPerTickTime;
        public float TickTime;
        public float3 RedCubeGeneratorPos;
        public float3 GreenCubeGeneratorPos;
        public float3 BlueCubeGeneratorPos;
        public float3 CubeTargetPos;
    }

    public class MultiCubesGeneratorAuthoring : MonoBehaviour
    {
        public GameObject RedCubeArchetype;
        public GameObject GreenCubeArchetype;
        public GameObject BlueCubeArchetype;
        public int GenerationTotalCount;
        public int GenerationNumPerTickTime;
        public float TickTime;
        public float3 RedCubeGeneratorPos;
        public float3 GreenCubeGeneratorPos;
        public float3 BlueCubeGeneratorPos;
        public float3 CubeTargetPos;


        class Baker : Baker<MultiCubesGeneratorAuthoring>
        {
            public override void Bake(MultiCubesGeneratorAuthoring authoring)
            {
                var entity = GetEntity(TransformUsageFlags.None);
                AddComponent(entity, new MultiCubesGenerator()
                {
                    RedCubeProtoType = GetEntity(authoring.RedCubeArchetype, TransformUsageFlags.Dynamic),
                    GreenCubeProtoType = GetEntity(authoring.GreenCubeArchetype, TransformUsageFlags.Dynamic),
                    BlueCubeProtoType = GetEntity(authoring.BlueCubeArchetype, TransformUsageFlags.Dynamic),
                    GenerationTotalCount = authoring.GenerationTotalCount,
                    GenerationNumPerTickTime = authoring.GenerationNumPerTickTime,
                    TickTime = authoring.TickTime,
                    RedCubeGeneratorPos = authoring.RedCubeGeneratorPos,
                    GreenCubeGeneratorPos = authoring.GreenCubeGeneratorPos,
                    BlueCubeGeneratorPos = authoring.BlueCubeGeneratorPos,
                    CubeTargetPos = authoring.CubeTargetPos,
                });
            }
        }
    }
}